/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tax;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Home
 */
public class CreateDataBase {
    public CreateDataBase(){
        try {
            Class.forName("org.sqlite.JDBC");
            Connection conn = DriverManager.getConnection("jdbc:sqlite:Tax.db");
            Statement stat = conn.createStatement();
            stat.executeUpdate("drop table if exists HoSo;");
            stat.executeUpdate("create table HoSo (STT integer, MaSoThue text, TenDoanhNghiep text, DiaChi Text, CongChucGiuNS text, TruongDoan text);");
            PreparedStatement prep = conn.prepareStatement(
                "insert into HoSo values (?, ?, ?, ?, ?, ?);");

            prep.setInt(1, 1);
            prep.setString(2, "123456");
            prep.setString(3, "XNK 1");
            prep.setString(4, "4A73");
            prep.setString(5, "Nguyen Van A");
            prep.setString(6, "Tran Van B");
            prep.addBatch();
            prep.setInt(1, 2);
            prep.setString(2, "B3456");
            prep.setString(3, "XNK 2");
            prep.setString(4, "4A73");
            prep.setString(5, "Nguyen Van A");
            prep.setString(6, "Tran Van B");
            prep.addBatch();
            
            conn.setAutoCommit(false);
            prep.executeBatch();
            conn.setAutoCommit(true);

            ResultSet rs = stat.executeQuery("select * from HoSo;");
            while (rs.next()) {
                System.out.println("STT = " + rs.getString("STT"));
                System.out.println("MaSoThue = " + rs.getString("MasoThue"));
            }
            rs.close();
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(CreateDataBase.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(CreateDataBase.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
